package org.xidea.commons.i18n;

public class DefaultCharsetSelector implements CharsetSelector {
	protected String defaultCharset = "utf-8";
	protected String latestSelectedCharset;

	public DefaultCharsetSelector() {
	}

	public DefaultCharsetSelector(String defaultCharset) {
		this.defaultCharset = defaultCharset;
	}

	public String selectCharset(String[] options) {
		if (defaultCharset != null) {
			for (int i = 0; i < options.length; i++) {
				if (defaultCharset.equalsIgnoreCase(options[i])) {
					return latestSelectedCharset = defaultCharset;
				}
			}
		}
		return latestSelectedCharset = options[0];
	}

	public String getLatestSelectedCharset() {
		return latestSelectedCharset;
	}

}
